using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace C4F.DevKit.PictureAcquisition
{
    /// <summary>
    /// .Net wrapper over interfaces for picture acquisition.
    /// </summary>
    internal class PictureAcquisitionNative
    {
        #region Interface imports
 
        /// <summary>
        /// .Net wrapper over IPhotoAcquire interface.
        /// </summary>
        [Guid("00f23353-e31b-4955-a8ad-ca5ebf31e2ce"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IPhotoAcquire
        {
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 CreatePhotoSource(
                string pszDevice,
                out IPhotoAcquireSource photoAcquireSource);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Acquire(
                    IPhotoAcquireSource pPhotoAcquireSource,
                    Int32 fShowProgress,
                    IntPtr hWndParent,
                    string pszApplicationName,
                    IntPtr pPhotoAcquireProgressCB);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 EnumResults(out IEnumString ppEnumFilePaths);
        }

        /// <summary>
        /// .Net wrapper over IEnumString interface.
        /// </summary>
        [Guid("00000101-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IEnumString
        {
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 RemoteNext([In] uint celt, [MarshalAs(UnmanagedType.LPWStr)] out string rgelt, out uint pceltFetched);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Skip([In] uint celt);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Reset();

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Clone([MarshalAs(UnmanagedType.Interface)] out IEnumString ppenum);
        }

        /// <summary>
        /// .Net wrapper over IPhotoAcquireDeviceSelectionDialog interface.
        /// </summary>
        [Guid("00f28837-55dd-4f37-aaf5-6855a9640467"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IPhotoAcquireDeviceSelectionDialog
        {
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetTitle([In, MarshalAs(UnmanagedType.LPWStr)] string pszTitle);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetSubmitButtonText([In, MarshalAs(UnmanagedType.LPWStr)] string pszSubmitButtonText);
            
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 DoModal(
                [In] IntPtr hWndParent, [In] UInt32 dwDeviceFlags,
                [Out, MarshalAs(UnmanagedType.BStr)] out string pbstrDeviceId,
                [Out] out UInt32 pnDeviceType);
        }

        /// <summary>
        /// .Net wrapper over IPhotoAcquireItem interface.
        /// </summary>
        [Guid("00f21c97-28bf-4c02-b842-5e4e90139a30"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IPhotoAcquireItem
        {
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetItemName(
                [MarshalAs(UnmanagedType.BStr)]out string pbstrItemName);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetThumbnail(
                  [In]  IntPtr sizeThumbnail,
                  [Out]  out IntPtr phbmpThumbnail);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetProperty(
                [In] IntPtr key,
                [Out] out IntPtr pv);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetProperty(
              [In] IntPtr key,
              [In] IntPtr pv);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetStream(
                [Out] out System.Runtime.InteropServices.ComTypes.IStream ppStream);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 CanDelete(
                [Out] out bool pfCanDelete);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Delete();

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetSubItemCount(
                [Out] out UInt32 pnCount);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetSubItemAt(
                [In] UInt32 nItemIndex,
                [Out] out IntPtr ppPhotoAcquireItem);
        }

        /// <summary>
        /// .Net wrapper over IPhotoAcquireOptionsDialog interface.
        /// </summary>
        [Guid("00f2b3ee-bf64-47ee-89f4-4dedd79643f2"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IPhotoAcquireOptionsDialog
        {           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Initialize(
                [In, MarshalAs(UnmanagedType.LPWStr)] string pszRegistryRoot);
          
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Create(
                 [In] IntPtr hWndParent,
                 [Out] out IntPtr phWndDialog);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 Destroy();
            
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 DoModal(
                [In] IntPtr hWndParent,
                [In, Out] ref Int32 ppnReturnCode);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SaveData();
        }
        
        /// <summary>
        /// .Net wrapper over IPhotoAcquireSettings interface.
        /// </summary>
        [Guid("00f2b868-dd67-487c-9553-049240767e91"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IPhotoAcquireSettings
        {                     
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 InitializeFromRegistry(
                  [In, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszRegistryKey);
                       
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetFlags(
            [In] UInt32 dwPhotoAcquireFlags);
                       
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetOutputFilenameTemplate(
                 [In, MarshalAs(UnmanagedType.LPWStr)] string pszTemplate);
                      
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetSequencePaddingWidth(
                 [In] UInt32 dwWidth);
                       
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetSequenceZeroPadding(
                 [In] Int32 fZeroPad);
                       
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetGroupTag(
                  [In, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszGroupTag);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 SetAcquisitionTime(
                 [In] System.Runtime.InteropServices.ComTypes.FILETIME pftAcquisitionTime);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetFlags(
                 [Out] out UInt32 pdwPhotoAcquireFlags);
          
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetOutputFilenameTemplate(
                 [Out, MarshalAs(UnmanagedType.BStr)] out string pbstrTemplate);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetSequencePaddingWidth(
                 [Out] out UInt32 pdwWidth);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetSequenceZeroPadding(
                 [Out] out bool pfZeroPad);
        
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetGroupTag(
                 [Out, MarshalAs(UnmanagedType.BStr)] out string pbstrGroupTag);
            
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetAcquisitionTime(
                  [Out] out System.Runtime.InteropServices.ComTypes.FILETIME pftAcquisitionTime);

        }

        /// <summary>
        /// .Net wrapper over IPhotoAcquireSource interface.
        /// </summary>
        [Guid("00f2c703-8613-4282-a53b-6ec59c5883ac"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IPhotoAcquireSource
        {
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetFriendlyName(
                [Out, MarshalAs(UnmanagedType.BStr)] out string pbstrFriendlyName);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetDeviceIcons(
                 [In] UInt32 nSize,
                 [In, Out] ref IntPtr phLargeIcon,
                 [In, Out] ref IntPtr phSmallIcon);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 InitializeItemList(
                [In] bool fForceEnumeration,
                [In] IntPtr pPhotoAcquireProgressCB,
                [Out] out UInt32 pnItemCount);
           
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetItemCount(
                [Out] out UInt32 pnItemCount);

            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetItemAt(
                [In] UInt32 nIndex,
                [Out] out IPhotoAcquireItem ppPhotoAcquireItem);

        
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetPhotoAcquireSettings(
                 [Out] out IPhotoAcquireSettings ppPhotoAcquireSettings);
                     
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 GetDeviceId(
                [Out, MarshalAs(UnmanagedType.BStr)] out StringBuilder pbstrDeviceId);
                      
            [PreserveSig]
            [return: MarshalAs(UnmanagedType.Error)]
            Int32 BindToObject(
                 [In] Guid riid,
                 [Out] out IntPtr ppv);

        }

        #endregion

        #region Class imports

        /// <summary>
        /// .Net wrapper over PhotoAcquire class.
        /// </summary>
        [ComImport, Guid("00f26e02-e9f2-4a9f-9fdd-5a962fb26a98")]
        internal class PhotoAcquire
        { }
        /// <summary>
        /// .Net wrapper over PhotoAcquireDeviceSelectionDialog class.
        /// </summary>
        [ComImport, Guid("00f29a34-b8a1-482c-bcf8-3ac7b0fe8f62")]
        internal class PhotoAcquireDeviceSelectionDialog
        { }
      
        /// <summary>
        /// .Net wrapper over PhotoAcquireOptionsDialog class.
        /// </summary>
        [ComImport, Guid("00f210a1-62f0-438b-9f7e-9618d72a1831")]
        internal class PhotoAcquireOptionsDialog
        { }
             
        #endregion
        
    }
}
